#机器学习方法
#人脸识别
import cv2
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
def face6Data():
    list=[]
    for i in range(5):
        for j in range(1,101):
            img=cv2.imread("ren/%s/%s.jpg"%(i,j))
            grayImg=cv2.cvtColor(img,code=cv2.COLOR_BGR2GRAY)
            list.append(grayImg)
    print()
    y=[]
    for i in range(5):
        y.append(i)
    y=y*100
    y=sorted(y)
    #print(y)
    list=np.array(list)
    y=np.array(y)
    #64x64=4096个像素，500张脸
    list=list.reshape(500, 4096)
    #100张脸，10%测试，90%训练
    x_train,x_test,y_train,y_test=train_test_split(list,y,test_size=0.1)

    label=["me","lrx","txy","cls","you"]
    knn=KNeighborsClassifier(5)
    knn.fit(x_train,y_train)
    for i in range(50):
        #自定义窗口
        cv2.namedWindow("who",flags=cv2.WINDOW_NORMAL)
        cv2.resizeWindow("who",width=300,height=300)
        cv2.imshow("who",x_test[i].reshape(64,64))
        print("这个人是:",label[y_test[i]])

        index=cv2.waitKey()
        if index==32:
            print("系统即将关闭......")
            break